{{!< default}}
{{> header background=@site.cover_image}} {{!--Special header.hbs partial to generate the <header> tag--}}
    <div class="inner">
        <div class="site-header-content">
            <h1 class="site-title">
                {{#if @site.logo}}
                    <img class="site-logo" src="{{img_url @site.logo size="l"}}" alt="{{@site.title}}" />
                {{else}}
                    {{@site.title}}
                {{/if}}
            </h1>
            <h2 class="site-description">{{@site.description}}</h2>
        </div>
    </div>
</header>
<div id='archivesBox' class='archives-box outer'>
</div>

<script src="https://cdn.bootcss.com/moment.js/2.24.0/moment.min.js"></script>
<script type = "text/javascript"> 


/**
 * 所需组件：moment.js
 * @auther blog.wstee.com
 */
jQuery(document).ready(function() {
	//获取所有文章数据，按照发表时间排列
	$.get({url:'/ghost/api/v2/content/posts/?key='+_ApiKey+'&limit=all'}).done(function(data) {
		console.log(data);
		var posts = data.posts;
		var count = posts.length;

        var html = "<div class='archives'></div>"
        $(html).appendTo('#archivesBox');
		$('.site-description').html('<div class="archives-posts-total">共计' + count + '篇文章</div>')
		for (var i = 0; i < count; i++) {
			//调用comentjs对时间戳进行操作
			var time = moment(posts[i].published_at);
			var year = time.get('y');
			var month = time.get('M')+1;
			var date = time.get('D');
			if( date<10 ) date = "0"+date;
			var title = posts[i].title;
			var url = posts[i].url;
			var excerpt = posts[i].excerpt;
			//首篇文章与其余文章分步操作
			if (i > 0) {
				var pre_month = moment(posts[i - 1].published_at).utcOffset("-08:00").get('month')+1;
				//如果当前文章的发表月份与前篇文章发表月份相同，则在该月份ul下插入该文章
				if (month == pre_month) {
					var html = "<li><div><time>"+date+"日</time><a href='"+url+"'>"+title+"</a><div class='archives-excerpt'>"+excerpt+"<div></div></li>";
					$(html).appendTo(".archives .list-"+year+"-"+month);
				}
				//当月份不同时，插入新的月份
				else{
					var html = "<div class='item'>"+"<h3><i class='fa fa-calendar fa-fw' aria-hidden='true'></i> "+year+"-"+month+"</h3><ul class='archives-list list-"+year+"-"+month+"'><li><time>"+date+"日</time><a href='"+url+"'>"+title+"</a><div class='archives-excerpt'>"+excerpt+"<div></li></ul></div>";
					$(html).appendTo('.archives');
				}
			}else{
				var html = "<div class='item'><h3><i class='fa fa-calendar fa-fw' aria-hidden='true'></i> "+year+"-"+month+"</h3><ul class='archives-list list-"+year+"-"+month+"'><li><time>"+date+"日</time><a href='"+url+"'>"+title+"</a><div class='archives-excerpt'>"+excerpt+"<div></li></ul></div>";
				$(html).appendTo('.archives');
			}
		}
	}).fail(function(err) {
		console.log(err);
	});
}); 
</script>